#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<string> ret;
    vector<string> binaryTreePaths(TreeNode* root) {
        string cur;
        _binary(root, cur);
        return ret;
    }
    void _binary(TreeNode* root, string cur)
    {
        if (root == nullptr) return;
        if (cur.size() == 0) cur = to_string(root->val);
        else cur += "->" + to_string(root->val);
        if (root->left == nullptr && root->right == nullptr)
        {
            ret.push_back(cur);
            return;
        }

        _binary(root->left, cur);
        _binary(root->right, cur);
    }
};